﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OrderControl
{
    class OrderService
    {
        public static List<Order> OrderList = new List<Order>();
        public static int OrderNumber = 0;
        //增加订单
        public static bool AddOrder(Order order)
        {
            foreach (Order o in OrderList)
            {
                if (o.Equals(order))
                {
                    return false;
                }
            }
            OrderList.Add(order);
            OrderNumber++;
            return true;
        }
        //删除订单
        public static void DeleteOrder(int orderNumber)
        {
            var query = from o in OrderList where o.OrderNumber != orderNumber select o;
            OrderList = query.ToList();
        }
        //查询订单
        public static void checkOrder(string orderusername)
        {
            var query = from o in OrderList where o.OrderUser == orderusername orderby o.OrderDate select o;
            List<Order> orderlist_ = query.ToList();
            foreach(Order o in orderlist_)
            {
                Console.WriteLine("---------------------------------------------------");
                Console.WriteLine("订单编号" + "\t" + "订单日期" + "\t" + "订单客户");
                Console.WriteLine(o.ToString());
                Console.WriteLine("商品名称" + "\t" + "商品单价" + "\t" + "商品数量");
                Console.WriteLine(o.orderItem.ToString());
                Console.WriteLine("订单总金额--------------------------------------" + o.amount);
            }            
        }
        //排序订单
        public static void Orderby()
        {
            var query = from o in OrderList orderby o.OrderDate select o;
            OrderList = query.ToList();
        }
    }
}
